﻿<%@ Page Language="c#" Inherits="TRPOP.CMS.Web.ExtraBus.BasePage" AutoEventWireup="true"
    EnableViewState="false" EnableTheming="false" %>

<%@ Import Namespace="TRPOP.Common" %>
<%@ Import Namespace="TRPOP.Config" %>
<%@ Import Namespace="TRPOP.CMS.Business" %>
<%@ Import Namespace="TRPOP.CMS.Model" %>

<script runat="server" type="text/C#">
    
    /// <summary>
    /// 自定义搜索条件
    /// </summary>
    /// <returns></returns>
    public string strGetCondation()
    {
        string strCondation = string.Empty;
        
        if (!RequestHelper.RequestString("nodeids").IsEmpty())
        {
            strCondation += " AND [NodeId] in (" + RequestHelper.RequestString("nodeids") + ") ";
        }

        if (!RequestHelper.RequestString("titles").IsEmpty())
        {
            strCondation += " AND [Name] like '%" + RequestHelper.RequestString("titles").SQLFilter() + "%'";
        }

        if (!RequestHelper.RequestString("sizes").IsEmpty())
        {
            strCondation += " AND  Keywords = '" + RequestHelper.RequestString("sizes").SQLFilter() + "'";
        }

        if (!RequestHelper.RequestString("company").IsEmpty())
        {
            strCondation += " AND  SubTitle = '" + RequestHelper.RequestString("company").SQLFilter() + "'";
        }

        if (!RequestHelper.RequestString("content").IsEmpty())
        {
            strCondation += " AND  Content  like '%" + RequestHelper.RequestString("content").SQLFilter() + "%'";
        }

        if (!RequestHelper.RequestString("startime").IsEmpty() && !RequestHelper.RequestString("startime_to").IsEmpty())
        {
            DateTime oStartTime = RequestHelper.RequestString("startime").ToDateTime();
            DateTime oEndTime = RequestHelper.RequestString("startime_to").ToDateTime();
            if (oStartTime == oEndTime || StringExtension.NullDateTime == oStartTime || StringExtension.NullDateTime == oEndTime)
            {
                ;
            }
            else
            {
                strCondation += " AND  ReleaseTime >=  '" + oStartTime.ToString() + "' AND ReleaseTime <=  '" + oEndTime.ToString() + "' ";
            }
        }

        if (!RequestHelper.RequestString("endtime").IsEmpty() && !RequestHelper.RequestString("endtime_to").IsEmpty())
        {
            DateTime oStartTime = RequestHelper.RequestString("endtime").ToDateTime();
            DateTime oEndTime = RequestHelper.RequestString("endtime_to").ToDateTime();
            if (oStartTime == oEndTime || StringExtension.NullDateTime == oStartTime || StringExtension.NullDateTime == oEndTime)
            {
                ;
            }
            else
            {
                strCondation += " AND  ImpTime   >=  '" + oStartTime.ToString() + "' AND ImpTime   <=  '" + oEndTime.ToString() + "' ";
            }
        }
        
        return strCondation;
        
    }
    
    protected override void OnInit(EventArgs e)
    {
        Site_Search();
    }

    /// <summary>
    /// 自定义搜索模板文件
    /// </summary>
    protected string GetPageSearchTemplate
    {
        get
        {
            return string.Empty; 
        } 
    }
    
    /// <summary>
    /// 网站搜索基本处理方法
    /// </summary>
    public void Site_Search()
    {
        Response.Clear();
        Response.ClearHeaders();
        Response.ClearContent();
        
        int intIndexID = RequestHelper.RequestInt("nodeid");        
        NodeInfo oNodeInfo = new NodeManage().GetInfoById(intIndexID);
        if (oNodeInfo == null)
        {
            TRPOP.CMS.Web.ExtraBus.Base_Config.NotFound(base.Page, "结点信息不存在(搜索)");
        }
                
        int o_intPageindex = RequestHelper.RequestInt("page");
        o_intPageindex = o_intPageindex <= 0 ? 1 : o_intPageindex;

        object obj = null;
        
        if (GetPageSearchTemplate.IsEmpty())
        {
            obj = TRPOP.CMS.Publish.PublishAccess.GetPageAdvancedSearch(oNodeInfo, strGetCondation(), o_intPageindex);
        }
        else
        {
            obj = TRPOP.CMS.Publish.PublishAccess.GetPageAdvancedSearch(oNodeInfo, strGetCondation(), o_intPageindex, GetPageSearchTemplate);
        }
        
        if (obj is string && obj.ToString().IsEmpty() == false)
        {
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.Write(obj.ToString());
            Response.End();
        }
        else
            TRPOP.CMS.Web.ExtraBus.Base_Config.NotFound(base.Page, "搜索页解析不正常或信息不存在");
    }
</script>